﻿//错误码
var ErrorCode =
{
    Unauthenticated: 516,
    Unauthorized: 518,
    CommonError: 520
};

//HTTP Method
var HttpMethod =
{
    Get: 'GET',
    Post: 'POST'
};

//修复ExtJS TreeStroe的刷新Bug
Ext.override
(
    Ext.data.TreeStore,
    {
        load: function (options)
        {
            options = options || {};
            options.params = options.params || {};

            var me = this,
                node = options.node || me.tree.getRootNode(),
                root;

            // If there is not a node it means the user hasnt defined a rootnode yet. In this case lets just create one for them.
            if (!node)
            {
                node = me.setRootNode
                (
                    {
                        expanded: true
                    }
                );
            }

            if (me.clearOnLoad)
            {
                // this is what we changed.  added false
                node.removeAll(false);
            }

            Ext.applyIf
            (
                options,
                {
                    node: node
                }
            );
            options.params[me.nodeParam] = node ? node.getId() : 'root';

            if (node)
            {
                node.set('loading', true);
            }

            return me.callParent([options]);
        }
    }
);

    var Common =
{
    //应用程序名称
    ApplicationName: '天水公路总段综合管理系统',

    //审核意见查看窗体
    win_comment_view: null,

    //处理错误
    HandleError: function (options, success, response) {
        //判定是否发生错误
        if (!success && options && options.failure) {
            //直接调用失败回调方法
            options.failure(response, options);

            //返回失败
            return false;
        }

        //判定是否有反馈对象
        if (!response) {
            //如果没有反馈对象，则直接返回结果
            return success;
        }

        //用于保存反馈对象
        var responseData = {};

        //解析反馈对象
        try {
            //解析反馈数据
            responseData = Ext.JSON.decode(response.responseText, false);
        }
        catch (error) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: response.responseText,
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.Msg.ERROR
                }
            );

            //返回
            return false;
        }

        //判定是否称成功
        if (responseData.success) {
            //如果成功，则直接返回
            return true;
        }

        //判定是否没有登录
        if (responseData.code == ErrorCode.Unauthenticated) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO
                }
            );

            //跳转到首页
            window.location = "/";
        }
        //判定是否没有授权
        else if (responseData.code == ErrorCode.Unauthorized) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }
        else {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }

        //默认返回失败
        return false;
    },
    //处理代理错误
    HandleProxyError: function (proxy, response, operation, options) {
        //用于保存反馈对象
        var responseData = {};

        //解析反馈对象
        try {
            //解析反馈数据
            responseData = Ext.JSON.decode(response.responseText, false);
        }
        catch (error) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: proxy.getError(),
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );

            //返回
            return false;
        }

        //判定是否称成功
        if (responseData.success) {
            //如果成功，则直接返回
            return true;
        }

        //判定是否没有登录
        if (responseData.code == ErrorCode.Unauthenticated) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO
                }
            );

            //跳转到首页
            window.location = "/";
        }
        //判定是否没有授权
        else if (responseData.code == ErrorCode.Unauthorized) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }
        else {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }

        //默认返回失败
        return false;
    },
    //处理页面失败
    HandleFormFailure: function (form, action) {
        //用于保存反馈对象
        var responseData = {};

        //解析反馈对象
        try {
            //解析反馈数据
            responseData = Ext.JSON.decode(action.response.responseText, false);
        }
        catch (error) {
            //用于保存错误信息 
            var message = '未知错误';

            //根据错误类型的不同分别处理
            switch (action.failureType) {
                //判定是否为数据无效                                                                                                                                                                                                                                               
                case Ext.form.action.Action.CLIENT_INVALID:
                    //设置错误信息
                    message = '提交的数据不合法';
                    break;
                case Ext.form.action.Action.CONNECT_FAILURE:
                    //设置错误信息
                    message = '无法连接服务器';
                    break;
                case Ext.form.action.Action.SERVER_INVALID:
                    message = action.result.message;
            }
            //返回
            return false;
        }

        //判定是否称成功
        if (responseData.success) {
            //如果成功，则直接返回
            return true;
        }

        //判定是否没有登录
        if (responseData.code == ErrorCode.Unauthenticated) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO
                }
            );

            //跳转到首页
            window.location = "/";
        }
        //判定是否没有授权
        else if (responseData.code == ErrorCode.Unauthorized) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }
        else {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }

        //默认返回失败
        return false;
    },
    //处理页面错误
    HandleFormError: function (form, action) {
        //用于保存反馈对象
        var responseData = {};

        //解析反馈对象
        try {
            //解析反馈数据
            responseData = Ext.JSON.decode(action.response.responseText, false);
        }
        catch (error) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: action.response.responseTex,
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.Msg.ERROR
                }
            );

            //返回
            return false;
        }

        //判定是否称成功
        if (responseData.success) {
            //如果成功，则直接返回
            return true;
        }

        //判定是否没有登录
        if (responseData.code == ErrorCode.Unauthenticated) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.INFO
                }
            );

            //跳转到首页
            window.location = "/";
        }
        //判定是否没有授权
        else if (responseData.code == ErrorCode.Unauthorized) {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }
        else {
            //提示错误信息
            Ext.MessageBox.show
            (
                {
                    title: Common.ApplicationName,
                    msg: responseData.message,
                    buttons: Ext.Msg.OK,
                    icon: Ext.Msg.ERROR
                }
            );
        }

        //默认返回失败
        return false;
    },
    //初始化附加字段验证类型
    InitAdditionalValidation: function () {
        //应用附加验证类型
        Ext.apply
        (
            Ext.form.field.VTypes,
            {
                //验证确认密码
                confirmPassword: function (val, field) {
                    //判定是否指定了初始密码字段
                    if (field.passwordField) {
                        //获得密码
                        var password = field.up('form').down('#' + field.passwordField);

                        //比较密码是否一致
                        return (val == password.getValue());
                    }
                    else {
                        //默认返回匹配
                        return true;
                    }
                },
                //提示文字
                confirmPasswordText: '确认密码和原始密码不一致',
                dateRange: function (val, field) {
                    //转换为日期
                    var date = field.parseDate(val);

                    //判断输入的日期是否合法
                    if (!date) {
                        //如果不合法，则设置为当前日期
                        date = new Date();
                    }

                    //设置开始日期的最大日期范围
                    if (field.beginDateField && (!this.dateRangeMax || (date.getTime() != this.dateRangeMax.getTime()))) {
                        //获得开始日期
                        var begin = field.up('form').down('#' + field.beginDateField);
                        //设置最大日期
                        begin.setMaxValue(date);
                        //记录最大日期
                        this.dateRangeMax = date;
                        begin.validate();
                    }
                    //设置结束日期的最小日期范围
                    else if (field.endDateField && (!this.dateRangeMin || (date.getTime() != this.dateRangeMin.getTime()))) {
                        //获得结束日期
                        var end = field.up('form').down('#' + field.endDateField);
                        //设置最小日期
                        end.setMinValue(date);
                        //记录最小日期
                        this.dateRangeMin = date;
                        end.validate();
                    }

                    //返回验证成功
                    return true;
                }
            }
        );
    },
    //生成绝对URL地址
    MakeAbsoluteUrl: function (url) {
        //判定是否为空地址
        if (!url || url.length == 0) {
            //如果是空地址，则直接返回
            return url;
        }

        //判定是否以/开头
        if (url.charAt(0) == '/') {
            //返回地址
            return ActionUrlRoot + url;
        }
        else {
            //返回地址
            return ActionUrlRoot + '/' + url;
        }
    },
    //生成控制器绝对URL地址
    MakeControllerUrl: function (controller, action) {
        //返回地址
        return HostUrl + '/' + controller + '/' + action;
    },
    //异步加载数据
    AsyncLoadData: function (url, params, target, value, field) {
        //创建请求对象
        Ext.Ajax.request
        (
            {
                url: url,
                params: params,
                method: HttpMethod.Get,
                callback: function (options, success, response) {
                    //判定是否发生错误
                    if (!success && options && options.failure) {
                        //直接返回
                        return;
                    }

                    //判定是否有反馈对象
                    if (!response) {
                        //直接返回
                        return;
                    }

                    //用于保存反馈对象
                    var responseData = {};

                    //解析反馈对象
                    try {
                        //解析反馈数据
                        responseData = Ext.JSON.decode(response.responseText, true);
                    }
                    catch (error) {
                        //直接返回
                        return;
                    }

                    //判定是否称成功
                    if (responseData.success) {
                        //加载数据
                        target.loadData(responseData.data);

                        //判定是否有值
                        if (value && field) {
                            //选中值
                            field.setValue(value);
                        }
                    }
                }
            }
        );
    },
    //计算周
    GetWeekOfYear: function (value) {
        try {
            //计算周数
            var week = Ext.Date.getWeekOfYear(value);

            //判断当天是否为星期天
            if (value.getDay() == 0) {
                //如果是星期天，则增加一周
                week += 1;
            }

            //返回周
            return week;
        }
        catch (e) {
            return null;
        }
    },
    //转换拼音
    ConvertToPinYin: function (source, target) {
        //创建请求对象
        Ext.Ajax.request
        (
            {
                url: PinYinUrl,
                params: { source: source },
                method: HttpMethod.Get,
                callback: function (options, success, response) {
                    //判定是否发生错误
                    if (!success && options && options.failure) {
                        //直接返回
                        return;
                    }

                    //判定是否有反馈对象
                    if (!response) {
                        //直接返回
                        return;
                    }

                    //用于保存反馈对象
                    var responseData = {};

                    //解析反馈对象
                    try {
                        //解析反馈数据
                        responseData = Ext.JSON.decode(response.responseText, true);
                    }
                    catch (error) {
                        //直接返回
                        return;
                    }

                    //判定是否称成功
                    if (responseData.success) {
                        //返回结果
                        target.setValue(responseData.data);
                    }
                }
            }
        );
    },
    //过期时间
    RendExpireDate: function (value) {
        try {
            //判断是否有数据
            if (value) {
                //判断是否过期
                if (value < new Date()) {
                    //格式化
                    return '<font color="gray">' + Ext.Date.format(value, 'Y/m/d H:i') + '</font>';
                }
                else {
                    //格式化
                    return '<font color="red">' + Ext.Date.format(value, 'Y/m/d H:i') + '</font>';
                }
            }
            else {
                return value;
            }
        }
        catch (e) {
            return e;
        }
    },
    //发布时间
    RendPostDate: function (value) {
        try {
            //判断是否有数据
            if (value) {
                //判断是否过期
                if (value < new Date()) {
                    //格式化
                    return '<font color="gray">' + Ext.Date.format(value, 'Y/m/d H:i') + '</font>';
                }
                else {
                    //格式化
                    return '<font color="green">' + Ext.Date.format(value, 'Y/m/d H:i') + '</font>';
                }
            }
            else {
                return value;
            }
        }
        catch (e) {
            return e;
        }
    },
    //版本
    RenderPlanVersion: function (value) {
        try {
            //判断状态值
            if (value <= 1) {
                //设置为1
                value = 1;

                //格式化
                return '<font color="green">' + Ext.String.leftPad(value, 2, '0') + '</font>';
            }
            else {
                //格式化
                return '<font color="red">' + Ext.String.leftPad(value, 2, '0') + '</font>';
            }
        }
        catch (e) {
            return e;
        }
    },
    //日期周
    RenderWeekOfYear: function (value) {
        try {
            //转换为日期
            value = new Date(value);

            //计算周数
            var week = Ext.Date.getWeekOfYear(value);

            //判断当天是否为星期天
            if (value.getDay() == 0) {
                //如果是星期天，则增加一周
                week += 1;
            }

            //返回显示字符串
            return value.getFullYear() + '年 第<font color="red">' + week + '</font>周';
        }
        catch (e) {
            return e;
        }
    },
    //工程状态
    RenderProjectState: function (value) {
        try {
            //判断状态值
            if (value == ProjectStateEnum.Unsubmit) {
                return '<font color="green">未提交</font>';
            }
            else if (value == ProjectStateEnum.Submitted) {
                return '<font color="green">待批准</font>';
            }
            else if (value == ProjectStateEnum.AuditRejected) {
                return '<font color="red">再提交</font>';
            }
            else if (value == ProjectStateEnum.Audited) {
                return '<font color="blue">已批准</font>';
            }
            else if (value == ProjectStateEnum.Closed) {
                return '<font color="gray">已关闭</font>';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    //数据状态
    RenderPostType: function (value) {
        try {
            //判断状态值
            if (value == 0) {
                return '<font color="red">所有单位</font>';
            }
            else if (value == 1) {
                return '<font color="green">指定单位</font>';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    //指令类型
    RenderInstructionType: function (value) {
        try {
            //判断状态值
            if (value == 0) {
                return '工程指令';
            }
            else if (value == 1) {
                return '养护指令';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    //指令标题
    RenderInstructionTitle: function (value, metaData, record, index, store, view) {
        try {
            var newPeriod = instruction_new_period | 7;
            var date = record.data.CreateDate;
            var endDate = new Date(date.valueOf() + newPeriod * 24 * 60 * 60 * 1000);
            if (endDate > (new Date())) {
                return '<font color="red">' + value + '</font>';
            } else
                return value;
        } catch (e) {
            return value;
        }
    },
    //数据状态
    RenderDataState: function (value) {
        try {
            //判断状态值
            if (value == DataStateEnum.Unsubmit) {
                return '<font color="green">待发布</font>';
            }
            else if (value == DataStateEnum.Submitted) {
                return '<font color="gray">已发布</font>';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    //渲染单位数量
    RenderNumber2WithUnit: function (value, metaData, record, index, store, view) {
        try {
            //返回数据
            return '<font color="green">' + Ext.util.Format.number(value, '0,000.00') + '</font> ' + record.data.Unit;
        }
        catch (e) {
            return value;
        }
    },
    //渲染单位数量
    RenderNumber3WithUnit: function (value, metaData, record, index, store, view) {
        try {
            //返回数据
            return '<font color="green">' + Ext.util.Format.number(value, '0,000.000') + '</font> ' + record.data.Unit;
        }
        catch (e) {
            return value;
        }
    },
    //养护数据状态
    RenderMaintainDataState: function (value, metaData, record, rowIndex, colIndex, store, view) {
        try {
            //判断状态值
            if (value == MaintainDataStateEnum.Unsubmit) {
                return '<font color="green">未提交</font>';
            }
            else if (value == MaintainDataStateEnum.Submitted) {
                return '<font color="green">待审核</font>';
            }
            else if (value == MaintainDataStateEnum.AuditRejected) {
                return '<font color="red">再提交</font>';
            }
            else if (value == MaintainDataStateEnum.Audited) {
                return '<font color="green">待批准</font>';
            }
            else if (value == MaintainDataStateEnum.ConfirmationRejected) {
                return '<font color="red">再审核</font>';
            }
            else if (value == MaintainDataStateEnum.Confirmed) {
                return '<font color="gray">已批准</font>';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    //工程数据状态
    RenderProjectDataState: function (value, metaData, record, rowIndex, colIndex, store, view) {
        try {
            //判断状态值
            if (value == ProjectDataStateEnum.Unsubmit) {
                return '<font color="green">未提交</font>';
            }
            else if (value == ProjectDataStateEnum.Submitted) {
                return '<font color="green">待审核</font>';
            }
            else if (value == ProjectDataStateEnum.AuditRejected) {
                return '<font color="red">再提交</font>';
            }
            else if (value == ProjectDataStateEnum.Audited) {
                return '<font color="green">待签审</font>';
            }
            else if (value == ProjectDataStateEnum.SignRejected) {
                return '<font color="red">再审核</font>';
            }
            else if (value == ProjectDataStateEnum.Signed) {
                return '<font color="green">待批准</font>';
            }
            else if (value == ProjectDataStateEnum.ConfirmationRejected) {
                return '<font color="red">再签审</font>'; ;
            }
            else if (value == ProjectDataStateEnum.Confirmed) {
                return '<font color="gray">已批准</font>';
            }
            else {
                return '未知';
            }
        }
        catch (e) {
            return e;
        }
    },
    AdjustGridWidth: function (gridID, containerID) {
        //获得容器
        var container = Ext.fly(containerID);

        //获得表格控件
        var grid = Ext.getCmp(gridID);

        //判断控件是否存在
        if (container && grid) {
            //获得宽度
            var width = Number(container.getWidth());
            //获得高度
            var height = Number(container.getHeight());

            //设置宽度
            grid.setWidth(width - 32);
            //设置高度
            grid.setHeight(height - 90);
        }
    },
    //查看审核意见
    ViewComment: function (owner) {
        //判定窗体是否已经创建
        if (!this.win_comment_view) {
            //创建窗体
            this.win_comment_view = Ext.create
            (
                'Ext.window.Window',
                {
                    title: '查看审核意见',
                    maximizable: false,
                    maximized: false,
                    width: 480,
                    height: 320,
                    autoScroll: false,
                    bodyBorder: false,
                    draggable: true,
                    isTopContainer: true,
                    modal: true,
                    resizable: false,
                    bodyPadding: 0,
                    closeAction: 'hide',
                    closable: false,
                    layout: 'fit',
                    listeners:
                    {
                        //挂接显示事件
                        show: function (win, options) {
                            //查询备注控件
                            var txtComment = win.down('#txtComment');

                            //判断是否存在备注控件
                            if (txtComment) {
                                //设置备注
                                txtComment.setValue(win.Comment);
                            }
                        }
                    },
                    items:
                    [
                        {
                            xtype: 'form',
                            frame: false,
                            bodyPadding: 12,
                            bodyStyle: 'background-color:White;margin:0;',
                            bodyBorder: false,
                            border: 0,
                            defaultType: 'textfield',
                            fieldDefaults:
                            {
                                labelAlign: 'left',
                                labelWidth: 72,
                                anchor: '100%'
                            },
                            items:
                            [
                                {
                                    xtype: 'textareafield',
                                    name: 'comment',
                                    readOnly: true,
                                    itemId: 'txtComment',
                                    height: '100%'
                                }
                            ],
                            buttons:
                            [
                                {
                                    text: '关闭',
                                    height: 26,
                                    margin: 3,
                                    handler: function () {
                                        //隐藏窗体
                                        this.up('window').hide();
                                    }
                                }
                            ]
                        }
                    ]
                }
            );
        }

        //设置审核意见
        this.win_comment_view.Comment = owner.title;

        //显示窗体
        this.win_comment_view.show();
    },
    AdjustReportSize: function (reportID, containerID) {
        //获得容器
        var container = Ext.fly(containerID);

        //获得报表容器
        var report = Ext.get(reportID);

        //判断控件是否存在
        if (container && report) {
            //获得宽度
            var width = Number(container.getWidth());
            //获得高度
            var height = Number(container.getHeight());

            //设置宽度
            report.setWidth(width - 32);
            //设置高度
            report.setHeight(height - 120);
        }
    },
    ScrollableRender: function (component) {
        component.getEl().on('touchstart', function (e) {
            if (e.browserEvent.touches[1]) {
                // Capture First Finger Position
                f1StartX = e.browserEvent.touches[0].pageX;
                f1StartY = e.browserEvent.touches[0].pageY;
                // Capture Second Finger Position
                f2StartX = e.browserEvent.touches[1].pageX;
                f2StartY = e.browserEvent.touches[1].pageY;
                // override the touch event’s normal functionality
                e.preventDefault();
            }
        });
        component.getEl().on('touchmove', function (e) {
            if (e.browserEvent.touches[1]) {
                //  Create Alias Variable Name
                var f1Touches = e.browserEvent.touches[0];
                var f2Touches = e.browserEvent.touches[1];

                //  y-axis
                // Capture the distance moved for each finger
                var f1TouchMovedY = f1StartY - f1Touches.pageY;
                var f2TouchMovedY = f2StartY - f2Touches.pageY;
                // Reset the start positions
                f1StartY = f1Touches.pageY;
                f2StartY = f2Touches.pageY;
                // Move only if both fingers moved in the same direction using
                // the coordinates from the finger that moved the farthest
                if (f1TouchMovedY > 0 && f2TouchMovedY > 0) {
                    var touchMoveY = Math.max(f1TouchMovedY, f2TouchMovedY);
                    component.scrollByDeltaY(touchMoveY);
                } else if (f1TouchMovedY < 0 && f2TouchMovedY < 0) {
                    var touchMoveY = Math.min(f1TouchMovedY, f2TouchMovedY);
                    component.scrollByDeltaY(touchMoveY);
                };


                //  x-axis
                // Capture the distance moved for each finger
                var f1TouchMovedX = f1StartX - f1Touches.pageX;
                var f2TouchMovedX = f2StartX - f2Touches.pageX;
                // Reset the start positions
                f1StartX = f1Touches.pageX;
                f2StartX = f2Touches.pageX;
                // Move only if both fingers moved in the same direction using
                // the coordinates from the finger that moved the farthest
                if (f1TouchMovedX > 0 && f2TouchMovedX > 0) {
                    var touchMoveX = Math.max(f1TouchMovedX, f2TouchMovedX);
                    component.scrollByDeltaX(touchMoveX);
                } else if (f1TouchMovedX < 0 && f2TouchMovedX < 0) {
                    var touchMoveX = Math.min(f1TouchMovedX, f2TouchMovedX);
                    component.scrollByDeltaX(touchMoveX);
                };
                // override the touch event’s normal functionality
                e.preventDefault();
            }
        });
    }
}

//定义日期比较器
Ext.define
(
    'DateComparer',
    {
        //构造函数
        constructor: function (config)
        {
            var me = this;
            Ext.apply(me, config);

            //创建相等比较函数
            me.Equal = me.createEqualFn();
        },

        //创建相等比较函数
        createEqualFn: function ()
        {
            var me = this,
            candidate = me.value;
            property = me.property;

            return function (item)
            {
                //获得用于比较的值
                var value = me.getRoot.call(me, item)[property];

                //判定是否相等
                if (candidate === null || value === null)
                {
                    return false;
                }

                //比较日期
                return candidate.getFullYear() === value.getFullYear() && candidate.getMonth() == value.getMonth() && candidate.getgetDay() == value.getDay();
            };
        },

        //获得根对象
        getRoot: function (item)
        {
            var root = this.root;
            return root === undefined ? item : item[root];
        }
    }
);

$(document).ready(function ()
{
    $(".menuRightButton").click(function ()
    {
        var target = $(this);
        var groupID = target.attr("data-group");
        var menu = $("ul[data-group=" + groupID + "]");
        var hide = target.attr("hide");
        if (hide == null || hide != "true")
        {
            menu.hide();
            target.attr("hide", true);
            target.addClass("menuRightButtonDown");
            target.removeClass("menuRightButtonUp");
        }
        else
        {
            menu.show();
            target.attr("hide", false);
            target.addClass("menuRightButtonUp");
            target.removeClass("menuRightButtonDown");
        }
    });
});